<?php

use App\Api\HouseController;
use App\Api\NoticeController;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;
use App\Api\LoginController;
use App\Api\CaptchaController;
use App\Api\ArticleController;
use App\Api\AdminController;
use App\Api\UploadController;
use App\Api\SystemController;
use App\Api\UsedController;
use App\Api\CarController;
use App\Api\PetController;
use App\Api\SwiperController;
use App\Api\AdController;
use App\Api\UserController;
use App\Api\SidershowController;
use App\Api\AuthController;
use App\Api\SearchController;
use App\Api\BigdataController;
use App\Api\RoleController;
use App\Api\PermissionController;


Route::get('captcha', [CaptchaController::class, 'create']);


Route::post('admin/login', [LoginController::class, 'login']);

/**
 * 登录用户信息
 */

/**
 * 后台管理
 */

Route::group(['prefix' => 'admin/', 'middleware' => ['auth:sanctum']], function () {
    //用户列表
    Route::apiResource('admin', AdminController::class);
    //登录用户信息
    Route::get('info', [AdminController::class, 'info']);

//    单个管理员
    Route::get('admin/{admin}', [AdminController::class, 'show']);

    //用户退出
    Route::post('logout', [AdminController::class, 'logout']);
    //文章模型管理

    Route::apiResource('article', ArticleController::class);
//房屋租赁
    Route::apiResource('article/{article}/house', HouseController::class);
    //公告
    Route::apiResource('article/{article}/notice', NoticeController::class);

    Route::post('system/edit', [SystemController::class, 'store']);
//二手市场
    Route::apiResource('article/{article}/used', UsedController::class);
    Route::apiResource('article/{article}/car', CarController::class);
    Route::apiResource('article/{article}/pet', PetController::class);
    Route::apiResource('article/{article}/ad', AdController::class);
    //幻灯片管理
    Route::apiResource('sidershow', SidershowController::class);
    //后台大数据
    Route::get('bigdata/index', [BigdataController::class, 'index']);
    Route::get('bigdata/count', [BigdataController::class, 'count']);

    /**
     * =============角色权限==========
     */
//角色
    Route::Resource('role', RoleController::class);
//获取管理员所有角色
    Route::get('admin/{admin}/roles', [RoleController::class, 'hasRoles']);
//    权限
    Route::get('permission', [PermissionController::class, 'edit']);
//    管理员所有权限
    Route::get('permission/admin', [PermissionController::class, 'admin']);
//获取角色的权限数据
    Route::get('role/{role}/permissions', [RoleController::class, 'permissions']);
//为角色设置权限
    Route::put('role/{role}/permission', [PermissionController::class, 'update']);

//为管理员设置角色
    Route::put('admin/{admin}/role', [RoleController::class, 'syncRoles']);


    /**
     * =============角色权限END==========
     */


});


//系统配置
Route::get('system', [SystemController::class, 'show']);

/**
 * 文件上传
 */
Route::post('upload/local', [UploadController::class, 'local']);
/**
 * wangEditor编辑器上传
 */
Route::post('upload/wangeditor', [UploadController::class, 'wangEditor']);

/**
 * 前台幻灯片接口
 */

Route::get('swiper', [SwiperController::class, 'index']);
/**
 * 首页区域
 */
Route::get('houseList', [HouseController::class, 'houseList']);
Route::get('carList', [CarController::class, 'carList']);
Route::get('usedList', [UsedController::class, 'usedList']);
Route::get('petList', [PetController::class, 'petList']);
Route::get('adList', [AdController::class, 'adList']);

/**
 * 首页区域END
 */

/**
 * house
 */
//列表页展示单页
Route::apiResource('article/{article}/house', HouseController::class)->only(['index', 'show']);
Route::apiResource('article/{article}/used', UsedController::class)->only(['index', 'show']);
Route::apiResource('article/{article}/pet', PetController::class)->only(['index', 'show']);
Route::apiResource('article/{article}/car', CarController::class)->only(['index', 'show']);
Route::apiResource('notice', NoticeController::class);
/**
 * 用户资料
 */
Route::get('user/info', [UserController::class, 'info'])->middleware(['auth:sanctum']);

/**
 * 普通用户登录
 */
Route::post('login', [AuthController::class, 'login']);
Route::post('logout', [AuthController::class, 'logout']);

Route::post('register', [AuthController::class, 'register']);

Route::post('search/search', [SearchController::class, 'search']);
Route::get('search/default', [SearchController::class, 'default']);

/**
 * 前台发布消息
 */

Route::get('article/publish', [ArticleController::class, 'publish']);

//修改用户资料

Route::put('user/update', [UserController::class, 'update']);
